$(function () {
    //======================
    //======设置查询条件========
    //======================
    //内部公司
    $("#zcfzb_toolbar [name='gsId']").gsjgtree(1);



    //搜索按钮
    $("#zcfzb_toolbar [name='searchButton']").click(function () {
        $(grid).datagrid({
            queryParams: {
                zcfzbStartDate: $("#zcfzb_toolbar [name='zcfzbStartDate']").val(),
                zcfzbEndDate: $("#zcfzb_toolbar [name='zcfzbEndDate']").val(),
                gsId:$("#zcfzb_toolbar [name='gsId']").val()
            }});
    });


    $("#btn_zcfzb_cbjz").click(function () {
        $.messager.confirm('提示', '是否进行销售成本结转?', function (r) {
            if (r) {
                $.ajax({
                    url: $.webPath() + "/report/zcfzb/cbjz_zcfzb",
                    dataType: 'json',
                    type: 'POST',
                    beforeSend: function () {
                        $.mask();
                    },
                    success: function (data) {
                        $.mask.hide();
                        if (data.statusCode == 200) {
                            $.messager.show({
                                title: '提示',
                                msg: data.message,
                                timeout: 3000,
                                showType: 'slide'
                            });
                            $("#zcfzb_toolbar [name='searchButton']").click();
                        } else {
                            $.messager.alert('提示', data.message, 'error');
                        }
                    },
                    error: function () {
                    }
                });
            }
        });
    });


//======================
//========统计列表========
//======================
    var columns = [
        [
            {field:'sbgs_mc', title:'物流园', width:17,align:'center'},
            {field:'kmmc', title:'科目名称', width:17,align:'center'},
            {field:'qcye', title:'期初余额', width:17,align:'center'},
            {field:'jf', title:'借方', width:17,align:'center'},
            {field:'df', title:'贷方', width:17,align:'center'},
            {field:'qm', title:'期末', width:17,align:'center'},
            {field: "xx", title: "详细", width: 17, align: 'center', formatter: function (value, row, index) {
                return '<a href="#" id="zcfzb_mx_qm" class="ye-linkbutton" style="color:yellowgreen" type="' + row["type"] + '" >' + '详细'+ '</a>';
            }}
        ]
    ];

    var grid = $('#zcfzb_grid').datagrid({
        url: $.webPath() + '/report/zcfzb/zcfzbList',
        toolbar: "#zcfzb_toolbar",
        rownumbers: true,
        singleSelect: true,
        collapsible: true,
        fit: true,
        pageNumber: 1,
        fitColumns: true,
        showFooter: true,
        queryParams: {
            zcfzbStartDate: $("#zcfzb_toolbar [name='zcfzbStartDate']").val(),
            zcfzbEndDate: $("#zcfzb_toolbar [name='zcfzbEndDate']").val()
        },
        columns: columns,
        onLoadSuccess: function () {
            var zcfzbStartDate =  $("#zcfzb_toolbar [name='zcfzbStartDate']").val();
            var zcfzbEndDate =  $("#zcfzb_toolbar [name='zcfzbEndDate']").val();
            $(".ye-linkbutton").linkbutton({plain: true}).unbind("click").bind("click", function () {
                $.window({
                    title: '资产负债表明细',
                    width: 1080,
                    height: 600,
                    cache: false,
                    maximizable: true,
                    url: $.webPath() + '/report/zcfzb/zcfzb_detail?type=' + $(this).attr("type") +'&&zcfzbStartDate=' +zcfzbStartDate +'&&zcfzbEndDate=' +zcfzbEndDate+'&&gsId=' +$("#zcfzb_toolbar [name='gsId']").val(),
                    modal: true,
                    buttons: []
                });
            });
        }
    });




});
